package org.bao.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bao.sms.AccountInfo;
import org.bao.sms.IndustrySMS;

/**
 * Servlet implementation class Sms
 */
@WebServlet("/Sms")
public class Sms extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取电话号码
		String phone_no = request.getParameter("usertel");
		System.out.println("电话号码为：" + phone_no);

		// 生成验证码
		String stryan = "";
		for (int i = 0; i < 6; i++) {
			double yanzhen_no = (Math.random() * 9) ;
			int yang1 = (int) Math.round(yanzhen_no);
			stryan += yang1;
		}
		System.out.println("验证码：" + stryan);

		// 获取开发者账号信息
		AccountInfo.execute();

		// 验证码通知短信接口
		IndustrySMS.execute(phone_no, stryan);

		// 发送
		PrintWriter pw = response.getWriter();
		pw.write(stryan);
		pw.flush();

	}

}
